// pages/activity/activity.js
//获取应用实例
const app = getApp()
var api = require('../../utils/api.js')
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowHeight: res.windowHeight,
        })
      }
    })
    that.bannerList();
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  bannerList: function () {
    var params = new Object();
    var that = this;
    api.POST({
      params: params,
      url: app.globalData.base_url + 'Event/index',
      success: function (res) {
        if (util.isEmpty(res.data.code)) {
          that.setData({
            bannerImg: res.data.data.img
          })
        }
      },
      fail: function (fail) {
        util.showError("登录失败，请检查网络");

      }
    })
  },
  sweepCode: function () {
    wx.scanCode({
      onlyFromCamera: true,
      success: (res) => {
        var scanCode = res.result;
        // wx.navigateTo({
        //   url: '../orderCode/orderCode?oid=4463094' ,
        // })
        if (scanCode.lastIndexOf("type=px") >= 0) {
          var shopId = scanCode.substring(scanCode.lastIndexOf("=") + 1);
          wx.navigateTo({
            url: '../classification/classification?index=2&shopId=' + shopId,
          })
        } else if (scanCode.lastIndexOf("type=oid") >= 0) {
          var oid = scanCode.substring(scanCode.lastIndexOf("=") + 1);
          wx.navigateTo({
            url: '../orderCode/orderCode?oid=' + oid,
          })
        } else {
          wx.navigateTo({
            url: '../pickup/pickup'
          })
        }
      },
      fail: function (e) {
        if (e.errMsg != 'scanCode:fail cancel') {
          util.showError("扫码失败");
        }
      }
    });
  },
})